<div id='login-account' class='weui-cells' style="margin-top: 20px;">
	<div class='weui-cell'>
		<div class='weui-cell__hd' style='width:70px;'>账号</div>
		<div class='weui-cell__bd'>
			<form onsubmit="$('#login-account-submit').trigger('click')">
				<input type='email' id='login-account-input' class='weui-input' name='account' placeholder="手机号码" />
			</form>
		</div>
	</div>
	<div class='weui-cell'>
		<div class='weui-cell__hd' style='width:70px;'>密码</div>
		<div class='weui-cell__bd'>
			<form onsubmit="$('#login-account-submit').trigger('click')">
				<input id='login-account-password-input' class='weui-input' type='password' name='password' placeholder="输入密码" />
			</form>
		</div>
	</div>
	<div class='weui-cell' id="login-account-vcode-cell" style='display: none;'>
		<div class='weui-cell__hd' style='width:70px;'>图形码</div>
		<div class='weui-cell__bd'>
			<form onsubmit="$('#login-account-submit').trigger('click')">
				<input type='email' id='login-account-vcode' class='login-vcode-input weui-input' name='vcode' placeholder="输入图形码" />
			</form>
		</div>
		<div class='weui-cell__ft'><img class='vcode'/></div>
	</div>
	<!--<label class="weui-cell weui-check__label login-auto">-->
		<!--<div class="weui-cell__hd">-->
			<!--<input checked="checked" id="login-account-auto" type="checkbox" class="weui-check" name="auto">-->
			<!--<i class="weui-icon weui-icon-checked"></i>-->
		<!--</div>-->
		<!--<div class="weui-cell__bd">-->
			<!--<small>自动登录</small>-->
		<!--</div>-->
	<!--</label>-->
</div>
<div class='errormsg' id="login-account-errormsg"></div>
<div class='weui-btn-area'>
	<button class='weui-btn weui-btn_primary' id='login-account-submit'>登录</button>
</div>
<div class="weui-cell__ft">
	<!--<a class='link' onclick="$('#login-tel-tab').trigger('click')" href='#password_resets'>忘记密码？</a>-->
</div>
<!--<div class='weui-cells__title'>还没有重卡汇账号？<a class='link' onclick="$('#login-tel-tab').trigger('click')">立即免费注册>></a></div>-->
<script>
    login_account = {
        init:function(){
            var a = $("#login-account-input");
            var p = $("#login-account-password-input");
            var v = $("#login-account-vcode");
            var c = $("#login-account-vcode-cell");
            var err = $("#login-account-errormsg");
            var email_reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            var tel_reg = /^1\d{10}$/
            var password_reg = /((?=.*\d)(?=.*\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}$/;
            POST.init("#login-account-submit",{
                stop:function(){
                    err.html('')
                    var account = a.val();
                    if(!tel_reg.test(account) && !email_reg.test(account)){
                        var errormsg = '请输入正确的账号'
                        err.html(errormsg);
                        alert(errormsg,' ',1);
                        a.focus();
                        return true;
                    }
                    var password = p.val();
                    if(!password_reg.test(password)){
                        var errormsg = '请输入正确的密码';
                        err.html(errormsg);
                        alert(errormsg,' ',1);
                        p.focus();
                        return true;
                    }
                },
                msg:{
                    "vcode error":"验证码不正确",
                    "password incorrect":"密码不正确",
                    "account not exist":"账号不存在",
                    "password not set":"密码未设置",
                },
                input:function(){
                    var auto = $("#login-account-auto").prop("checked")?1:0;
                    return {account:a.val(),password:p.val(),vcode:v.val(),auto:auto}
                },
                text:"登录",
                success:function(){
                    err.html('');
                    $('#login-account input').val('');
                    $(document).trigger('login-success');
                    $(document).trigger('login-success-account');
                    window.location.reload();
                },
                url:"http://api.hongyanche.com/login/account_check",
                error:function(e,res){
                    switch(res.errormsg){
                        case "vcode error":
                            c.fadeIn();
                            $(".vcode").addClass("active");
                            $(".vcode").attr('src','http://api.hongyanche.com/vcode');
                            v.val('');
                            v.focus();
                            break;
                        case "account not exist":
                            a.focus();
                            c.hide();
                            break;
                        case "password not set":
                        case "password incorrect":
                            p.focus();
                            c.hide();
                        default:
                            c.hide();
                            break;
                    }
                    var errormsg = this.msg[res.errormsg] || res.errormsg;
                    err.html(errormsg);
                }
            })
        }
    }
    $(function(){
        login_account.init();
    })
</script>